package com.oo.packaging_2.subject;

/**
 * Student--${description}
 *
 * @author: Jovi
 * @createTime: 2017-04-19 16:46
 **/
public class Student {

    private int studentNo;

    private String name;

    private int age;

    private Subject subject;

    public Student(int studentNo, String name, int age, Subject subject) {
        this.studentNo = studentNo;
        this.name = name;
        this.setAge(age);
        this.setSubject(subject);
    }

    public Student() {
    }

    public int getStudentNo() {
        return studentNo;
    }

    public void setStudentNo(int studentNo) {
        this.studentNo = studentNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age < 18) {
            System.out.println("年龄小于18岁");
        }else
        this.age = age;
    }

    public Subject getSubject() {
        return subject;
    }

    public void setSubject(Subject subject) {
        int number  = subject.getCount();
        number++;
        subject.setCount(number);
        this.subject = subject;
    }

    public void learn() {
        System.out.println("我叫"+getName()+"，今年"+getAge()+"岁\n现在就读于"
        +getSubject().getsName()+"，我的学号是："+getStudentNo());
    }
}
